#include "stdafx.h"

#include "app/test_core.h"
#include "core/engine.h"
#include "util/profiler.h"
#include "util/stringutil.h"

namespace natrium {
	namespace app {
		TestCore::TestCore(): 
			Application("TEST", core::Task::SINGLETHREADED_REPEATING)
		{
			using namespace input;
			using namespace core;

			mChan.add<Keyboard::KeyPressed>(&[](const Keyboard::KeyPressed& kp) {
				if (kp.mKey == GLFW_KEY_ESC) {
					EventChannel chan;
					Kernel::StopEvent stop;
					chan.broadcast(stop);
				}
			});

			mChan.add<Keyboard::KeyPressed>(this);

			mConfigInt = 123;
			mConfigFloat = 45.6f;
			mConfigBool = false;

			addSetting("CFGINT", &mConfigInt);
			addSetting("CFGFLT", &mConfigFloat);
			addSetting("CFGBOOL", &mConfigBool);
		}

		TestCore::~TestCore() {
		}

		bool TestCore::init() {
			System::init();
		
			gLog << "TestCore initialized!";
			gLog << "Test int: " << mConfigInt;
			gLog << "Test flt: " << mConfigFloat;
			gLog << "Test bool: " << util::toString(mConfigBool);
		
			return true;
		}

		void TestCore::update() {
			//System::update doesn't do anything
			__PROFILE
		
			std::this_thread::sleep_for(std::chrono::milliseconds(1000));
		}

		void TestCore::shutdown() {
			gLog << "TestCore shutting down";
			System::shutdown();
		}

		void TestCore::operator()(const input::Keyboard::KeyPressed& kp) {
			gLog << "Key pressed: " << kp.mKey;
		}
	}
}